<template>
    <el-dialog :close-on-click-modal="false"
               title="新增跟进记录"
               :visible.sync="visible">
        <el-form ref="dataForm"
                 :model="dataForm"
                 label-width="100px"
                 @keyup.enter.native="dataFormSubmit()">


            <el-form-item label="跟踪描述"
                          prop="traceDesc">
                <el-input v-model="dataForm.traceDesc"></el-input>
            </el-form-item>

            <el-form-item label="客户反馈意见"
                          prop="cusFeedback">
              <el-input v-model="dataForm.cusFeedback"></el-input>
            </el-form-item>

            <el-form-item label="跟踪时间"
                          prop="traceTime">
              <el-date-picker
                  v-model="dataForm.traceTime"
                  type="datetime"
                  placeholder="选择日期时间"
                  format="yyyy-MM-dd HH:mm:ss"
                  value-format="yyyy-MM-dd HH:mm:ss">
              </el-date-picker>
            </el-form-item>
        </el-form>
        <span slot="footer"
              class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary"
                 @click="dataFormSubmit()">确定</el-button>
    </span>
    </el-dialog>
</template>

<script>
import {Debounce} from '@/utils/debounce'
import {khhyList, sjTypeList} from '@/utils/data'

export default {
    data () {
        return {
            visible: false,
            roleList: [],
            personList: [],
            sjTypeList: khhyList,
            custIndustryList: [],
            custList: [],
            provinceList: [],
            cityList: [],
            areaList: [],
            dataForm: {
                id: null,
                traceDesc: '',
                traceTime: '',
                cusFeedback: '',

            }
        }
    },
    methods: {
        init (id) {
            console.info("-----oppoid-----")
            console.info(id)
            this.dataForm.busiOppoId = id || ''
            this.dataForm.id = id || ''
            this.visible = true
            this.$nextTick(() => {
                this.$refs['dataForm'].resetFields()

            })
        },
        changeDisCover(){
            this.dataForm.currTraceMan = this.dataForm.discoverMan
        },
        listAreaByParentId (pid) {
            if (!pid) pid = 0
            return this.$http({
                url: this.$http.adornUrl(`/admin/area/listByPid`),
                method: 'get',
                params: this.$http.adornParams({pid})
            })
        },
        // 选择省
        selectProvince (val) {
            this.dataForm.cusCity = null
            this.dataForm.city = ''
            // 获取城市的select
            this.listAreaByParentId(val).then(({data}) => {
                this.cityList = data
            })
        },
        // 选择市
        selectCity (val) {
            this.dataForm.areaId = null
            this.dataForm.area = ''
            // 获取区的select
            this.listAreaByParentId(val).then(({data}) => {
                this.areaList = data
            })
        },
        // 表单提交
        dataFormSubmit: Debounce(function () {
            this.$refs['dataForm'].validate((valid) => {
              console.info(this.dataForm);
                if (valid) {
                    this.$http({
                        url: this.$http.adornUrl( '/crm/oppo/addBusiOppoTrace'),
                        method: 'post',
                        data: this.$http.adornData({
                            ...this.dataForm,
                            traceStauts: '1',
                            id: wfy.uuid(32)
                        })
                    }).then(({data}) => {
                        this.$message({
                            message: '操作成功',
                            type: 'success',
                            duration: 1500,
                            onClose: () => {
                                this.visible = false
                                this.$emit('refreshDataList')
                            }
                        })
                    })
                }
            })
        })
    }
}
</script>
